source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-313.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.367.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
5650 8387 8522 8402 1981 1190 3107 3207 4030 4740 949 3526 5637 4720 1852 87
17 18 19 20 21 22 23 24 25
739 2617 5677 5211 1364 3683 4036 2975 2592
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
precip longitud latitud altitud
[1,] -0.04032153 0.6465287 0.73799492 0.2886422
[2,] 0.36501065 0.5450317 -0.06942733 0.4845284
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud latitud altitud precip
0.9768367 0.9609975 0.9567491 0.9142196
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.497 Mean :217.5 Mean :150.7 Mean : 6.631 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :130.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03099 Mean :28.36 Mean :-16.05 Mean : 519.8
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:146.0 1st Qu.: 50.00 1st Qu.: 3.00
Median : 6.000 Median :194.0 Median : 93.00 Median : 11.00
Mean : 6.496 Mean :198.9 Mean : 94.85 Mean : 16.81
3rd Qu.: 9.000 3rd Qu.:255.0 3rd Qu.: 141.00 3rd Qu.: 23.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :163.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.99 1st Qu.: -4.8500
Median :0.000000 Median : 0.0000 Median :40.96 Median : -2.4831
Mean :0.000318 Mean : 0.4932 Mean :40.54 Mean : -2.4512
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.23 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.0
Mean : 410.5
3rd Qu.: 667.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:109.0 1st Qu.: 47.00 1st Qu.:171.0 1st Qu.:0
Median : 9.000 Median :129.0 Median : 72.00 Median :186.0 Median :0
Mean : 7.207 Mean :137.7 Mean : 74.05 Mean :203.4 Mean :0
3rd Qu.:11.000 3rd Qu.:152.5 3rd Qu.: 92.00 3rd Qu.:220.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -8.624 1st Qu.: 95.0
Median : 0.00 Median :42.24 Median : -8.411 Median : 263.0
Mean : 8.23 Mean :40.70 Mean : -6.597 Mean : 566.3
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2400.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.497 Mean :217.5 Mean :150.7 Mean : 6.631 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :130.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03099 Mean :28.36 Mean :-16.05 Mean : 519.8
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:148.0 1st Qu.: 49.00 1st Qu.: 3.00
Median : 6.000 Median :197.0 Median : 94.00 Median : 10.00
Mean : 6.457 Mean :200.9 Mean : 95.14 Mean : 13.54
3rd Qu.: 9.000 3rd Qu.:258.0 3rd Qu.: 143.00 3rd Qu.: 20.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :122.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.99 1st Qu.:-4.8500
Median :0.000000 Median : 0.0000 Median :40.95 Median :-2.4831
Mean :0.000338 Mean : 0.4955 Mean :40.50 Mean :-2.3879
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 261.0
Mean : 423.2
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. : 42.00
1st Qu.: 3.000 1st Qu.:134.0 1st Qu.: 62.00 1st Qu.: 53.00
Median : 9.000 Median :162.0 Median : 86.00 Median : 64.00
Mean : 7.147 Mean :166.6 Mean : 90.07 Mean : 70.73
3rd Qu.:11.000 3rd Qu.:196.0 3rd Qu.: 117.00 3rd Qu.: 81.00
Max. :12.000 Max. :352.0 Max. : 219.00 Max. :163.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.: -6.257
Median :0 Median : 0.0000 Median :42.24 Median : -3.788
Mean :0 Mean : 0.4554 Mean :41.14 Mean : -3.494
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.033
Max. :0 Max. :892.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 29.0
Median : 91.1
Mean : 201.6
3rd Qu.: 261.0
Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:109.0 1st Qu.: 47.00 1st Qu.:171.0 1st Qu.:0
Median : 9.000 Median :129.0 Median : 72.00 Median :186.0 Median :0
Mean : 7.207 Mean :137.7 Mean : 74.05 Mean :203.4 Mean :0
3rd Qu.:11.000 3rd Qu.:152.5 3rd Qu.: 92.00 3rd Qu.:220.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -8.624 1st Qu.: 95.0
Median : 0.00 Median :42.24 Median : -8.411 Median : 263.0
Mean : 8.23 Mean :40.70 Mean : -6.597 Mean : 566.3
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2400.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.497 Mean :217.5 Mean :150.7 Mean : 6.631 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :130.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03099 Mean :28.36 Mean :-16.05 Mean : 519.8
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:152.0 1st Qu.: 52.00 1st Qu.: 3.00
Median : 6.000 Median :200.0 Median : 96.00 Median :10.00
Mean : 6.456 Mean :204.7 Mean : 97.84 Mean :12.87
3rd Qu.: 9.000 3rd Qu.:261.0 3rd Qu.: 145.00 3rd Qu.:20.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :65.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-4.8500
Median :0.000000 Median : 0.00000 Median :40.95 Median :-2.6544
Mean :0.000349 Mean : 0.06075 Mean :40.46 Mean :-2.4598
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 0.4914
Max. :6.000000 Max. :229.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.0
Mean : 367.6
3rd Qu.: 656.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. : 42.00
1st Qu.: 3.000 1st Qu.:134.0 1st Qu.: 62.00 1st Qu.: 53.00
Median : 9.000 Median :162.0 Median : 86.00 Median : 64.00
Mean : 7.147 Mean :166.6 Mean : 90.07 Mean : 70.73
3rd Qu.:11.000 3rd Qu.:196.0 3rd Qu.: 117.00 3rd Qu.: 81.00
Max. :12.000 Max. :352.0 Max. : 219.00 Max. :163.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.: -6.257
Median :0 Median : 0.0000 Median :42.24 Median : -3.788
Mean :0 Mean : 0.4554 Mean :41.14 Mean : -3.494
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.033
Max. :0 Max. :892.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 29.0
Median : 91.1
Mean : 201.6
3rd Qu.: 261.0
Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:109.0 1st Qu.: 47.00 1st Qu.:171.0 1st Qu.:0
Median : 9.000 Median :129.0 Median : 72.00 Median :186.0 Median :0
Mean : 7.207 Mean :137.7 Mean : 74.05 Mean :203.4 Mean :0
3rd Qu.:11.000 3rd Qu.:152.5 3rd Qu.: 92.00 3rd Qu.:220.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -8.624 1st Qu.: 95.0
Median : 0.00 Median :42.24 Median : -8.411 Median : 263.0
Mean : 8.23 Mean :40.70 Mean : -6.597 Mean : 566.3
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2400.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 19.00
Median : 6.000 Median : 72.00 Median : 6.00 Median : 30.00
Mean : 6.482 Mean : 80.96 Mean : 11.65 Mean : 34.35
3rd Qu.:10.000 3rd Qu.:131.00 3rd Qu.: 56.25 3rd Qu.: 47.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :122.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1572
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.9844 Median :2228
Mean :0 Mean : 13.97 Mean :41.99 Mean :-0.1576 Mean :2145
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :169.0 Median : 1.000 Median :0
Mean : 6.478 Mean :234.1 Mean :169.6 Mean : 5.838 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :73.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.000354 Mean :28.38 Mean :-15.95 Mean :129.9
3rd Qu.:0.000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:152.0 1st Qu.: 52.00 1st Qu.: 3.00
Median : 6.000 Median :200.0 Median : 96.00 Median :10.00
Mean : 6.456 Mean :204.7 Mean : 97.84 Mean :12.87
3rd Qu.: 9.000 3rd Qu.:261.0 3rd Qu.: 145.00 3rd Qu.:20.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :65.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-4.8500
Median :0.000000 Median : 0.00000 Median :40.95 Median :-2.6544
Mean :0.000349 Mean : 0.06075 Mean :40.46 Mean :-2.4598
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 0.4914
Max. :6.000000 Max. :229.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.0
Mean : 367.6
3rd Qu.: 656.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. : 42.00
1st Qu.: 3.000 1st Qu.:134.0 1st Qu.: 62.00 1st Qu.: 53.00
Median : 9.000 Median :162.0 Median : 86.00 Median : 64.00
Mean : 7.147 Mean :166.6 Mean : 90.07 Mean : 70.73
3rd Qu.:11.000 3rd Qu.:196.0 3rd Qu.: 117.00 3rd Qu.: 81.00
Max. :12.000 Max. :352.0 Max. : 219.00 Max. :163.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.: -6.257
Median :0 Median : 0.0000 Median :42.24 Median : -3.788
Mean :0 Mean : 0.4554 Mean :41.14 Mean : -3.494
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.033
Max. :0 Max. :892.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 29.0
Median : 91.1
Mean : 201.6
3rd Qu.: 261.0
Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 50.50 Median : 3.00 Median :0
Mean : 6.588 Mean :138.4 Mean : 60.82 Mean : 10.39 Mean :0
3rd Qu.:10.000 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :130.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1765 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:109.0 1st Qu.: 47.00 1st Qu.:171.0 1st Qu.:0
Median : 9.000 Median :129.0 Median : 72.00 Median :186.0 Median :0
Mean : 7.207 Mean :137.7 Mean : 74.05 Mean :203.4 Mean :0
3rd Qu.:11.000 3rd Qu.:152.5 3rd Qu.: 92.00 3rd Qu.:220.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -8.624 1st Qu.: 95.0
Median : 0.00 Median :42.24 Median : -8.411 Median : 263.0
Mean : 8.23 Mean :40.70 Mean : -6.597 Mean : 566.3
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2400.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 19.00
Median : 6.000 Median : 72.00 Median : 6.00 Median : 30.00
Mean : 6.482 Mean : 80.96 Mean : 11.65 Mean : 34.35
3rd Qu.:10.000 3rd Qu.:131.00 3rd Qu.: 56.25 3rd Qu.: 47.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :122.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1572
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.9844 Median :2228
Mean :0 Mean : 13.97 Mean :41.99 Mean :-0.1576 Mean :2145
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :169.0 Median : 1.000 Median :0
Mean : 6.478 Mean :234.1 Mean :169.6 Mean : 5.838 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :73.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.000354 Mean :28.38 Mean :-15.95 Mean :129.9
3rd Qu.:0.000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 8.0 Min. :-68.0 Min. : 0.00
1st Qu.: 4.000 1st Qu.:169.0 1st Qu.: 70.0 1st Qu.: 2.00
Median : 6.000 Median :215.0 Median :115.0 Median : 7.00
Mean : 6.446 Mean :219.3 Mean :115.8 Mean :10.07
3rd Qu.: 9.000 3rd Qu.:272.0 3rd Qu.:165.0 3rd Qu.:15.00
Max. :12.000 Max. :403.0 Max. :254.0 Max. :48.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :35.28 Min. :-6.9492
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:37.79 1st Qu.:-2.9553
Median :0.000000 Median : 0.0000 Median :39.85 Median : 0.3664
Mean :0.000286 Mean : 0.0214 Mean :39.66 Mean :-1.0267
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.63 3rd Qu.: 1.1789
Max. :4.000000 Max. :59.0000 Max. :43.49 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 21.0
Median : 69.0
Mean :140.3
3rd Qu.:192.0
Max. :953.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. : 42.00
1st Qu.: 3.000 1st Qu.:134.0 1st Qu.: 62.00 1st Qu.: 53.00
Median : 9.000 Median :162.0 Median : 86.00 Median : 64.00
Mean : 7.147 Mean :166.6 Mean : 90.07 Mean : 70.73
3rd Qu.:11.000 3rd Qu.:196.0 3rd Qu.: 117.00 3rd Qu.: 81.00
Max. :12.000 Max. :352.0 Max. : 219.00 Max. :163.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.: -6.257
Median :0 Median : 0.0000 Median :42.24 Median : -3.788
Mean :0 Mean : 0.4554 Mean :41.14 Mean : -3.494
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.033
Max. :0 Max. :892.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 29.0
Median : 91.1
Mean : 201.6
3rd Qu.: 261.0
Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 50.50 Median : 3.00 Median :0
Mean : 6.588 Mean :138.4 Mean : 60.82 Mean : 10.39 Mean :0
3rd Qu.:10.000 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :130.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1765 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:123.0 1st Qu.: 23.00 1st Qu.: 3.00
Median : 6.000 Median :183.0 Median : 66.00 Median : 9.00
Mean : 6.484 Mean :191.8 Mean : 71.34 Mean :12.15
3rd Qu.: 9.000 3rd Qu.:261.0 3rd Qu.: 117.00 3rd Qu.:18.00
Max. :12.000 Max. :400.0 Max. : 250.00 Max. :65.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :37.13 Min. :-6.600
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.07 1st Qu.:-4.680
Median :0.000000 Median : 0.0000 Median :40.70 Median :-3.764
Mean :0.000498 Mean : 0.1203 Mean :40.67 Mean :-3.352
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.65 3rd Qu.:-2.138
Max. :6.000000 Max. :229.0000 Max. :42.70 Max. : 2.438
altitud
Min. : 405.0
1st Qu.: 627.0
Median : 735.0
Mean : 777.2
3rd Qu.: 916.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:109.0 1st Qu.: 47.00 1st Qu.:171.0 1st Qu.:0
Median : 9.000 Median :129.0 Median : 72.00 Median :186.0 Median :0
Mean : 7.207 Mean :137.7 Mean : 74.05 Mean :203.4 Mean :0
3rd Qu.:11.000 3rd Qu.:152.5 3rd Qu.: 92.00 3rd Qu.:220.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -8.624 1st Qu.: 95.0
Median : 0.00 Median :42.24 Median : -8.411 Median : 263.0
Mean : 8.23 Mean :40.70 Mean : -6.597 Mean : 566.3
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2400.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 7.0 Min. :-62.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:143.0 1st Qu.: 65.00 1st Qu.:16.00
Median : 6.000 Median :179.0 Median : 96.00 Median :26.00
Mean : 6.419 Mean :180.8 Mean : 96.97 Mean :26.18
3rd Qu.: 9.000 3rd Qu.:219.0 3rd Qu.:133.00 3rd Qu.:36.00
Max. :12.000 Max. :340.0 Max. :202.00 Max. :59.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :39.47 Min. :-8.649
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:42.85 1st Qu.:-8.411
Median :0.0000000 Median : 0.00000 Median :43.31 Median :-5.873
Mean :0.0001935 Mean : 0.05853 Mean :43.11 Mean :-5.845
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:43.43 3rd Qu.:-3.819
Max. :2.0000000 Max. :40.00000 Max. :43.57 Max. :-1.008
altitud
Min. : 4.0
1st Qu.: 42.0
Median :108.0
Mean :176.5
3rd Qu.:336.0
Max. :656.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 19.00
Median : 6.000 Median : 72.00 Median : 6.00 Median : 30.00
Mean : 6.482 Mean : 80.96 Mean : 11.65 Mean : 34.35
3rd Qu.:10.000 3rd Qu.:131.00 3rd Qu.: 56.25 3rd Qu.: 47.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :122.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1572
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.9844 Median :2228
Mean :0 Mean : 13.97 Mean :41.99 Mean :-0.1576 Mean :2145
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :169.0 Median : 1.000 Median :0
Mean : 6.478 Mean :234.1 Mean :169.6 Mean : 5.838 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :73.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.000354 Mean :28.38 Mean :-15.95 Mean :129.9
3rd Qu.:0.000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 95.0 Min. :-17.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:182.0 1st Qu.: 93.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :227.0 Median :132.0 Median : 5.000 Median :0
Mean : 6.436 Mean :234.4 Mean :132.1 Mean : 9.398 Mean :0
3rd Qu.: 9.000 3rd Qu.:281.0 3rd Qu.:175.0 3rd Qu.:16.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :246.0 Max. :42.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.949 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:36.50 1st Qu.:-6.332 1st Qu.: 19.00
Median : 0.00000 Median :36.83 Median :-5.616 Median : 32.00
Mean : 0.01392 Mean :36.87 Mean :-5.396 Mean : 55.37
3rd Qu.: 0.00000 3rd Qu.:37.26 3rd Qu.:-4.846 3rd Qu.: 87.00
Max. :34.00000 Max. :38.88 Max. :-1.229 Max. :200.00
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. : 8.0 Min. :-68.0 Min. : 0.00
1st Qu.: 3.00 1st Qu.:163.0 1st Qu.: 63.0 1st Qu.: 3.00
Median : 6.00 Median :209.0 Median :105.0 Median : 8.00
Mean : 6.45 Mean :213.6 Mean :109.6 Mean :10.32
3rd Qu.: 9.00 3rd Qu.:269.0 3rd Qu.:160.0 3rd Qu.:15.00
Max. :12.00 Max. :386.0 Max. :254.0 Max. :48.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :36.85 Min. :-3.8314
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.: 0.0406
Median :0.000000 Median : 0.00000 Median :41.29 Median : 0.6181
Mean :0.000395 Mean : 0.02423 Mean :40.72 Mean : 0.6246
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.83 3rd Qu.: 1.8744
Max. :4.000000 Max. :59.00000 Max. :43.49 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 29.0
Median : 81.0
Mean :172.4
3rd Qu.:263.0
Max. :953.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 42.0 Min. :-42.00 Min. : 42.0 Min. :0
1st Qu.: 3.000 1st Qu.:137.0 1st Qu.: 63.00 1st Qu.: 52.0 1st Qu.:0
Median : 9.000 Median :165.0 Median : 88.00 Median : 61.0 Median :0
Mean : 7.068 Mean :169.6 Mean : 91.69 Mean : 63.1 Mean :0
3rd Qu.:11.000 3rd Qu.:199.0 3rd Qu.:119.00 3rd Qu.: 73.0 3rd Qu.:0
Max. :12.000 Max. :352.0 Max. :219.00 Max. :112.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.48 1st Qu.: -6.0442 1st Qu.: 27.1
Median : 0.00000 Median :42.24 Median : -2.9056 Median : 90.0
Mean : 0.05426 Mean :41.09 Mean : -3.2526 Mean : 182.8
3rd Qu.: 0.00000 3rd Qu.:43.31 3rd Qu.: 0.0714 3rd Qu.: 261.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :1405.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 50.50 Median : 3.00 Median :0
Mean : 6.588 Mean :138.4 Mean : 60.82 Mean : 10.39 Mean :0
3rd Qu.:10.000 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :130.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1765 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:123.0 1st Qu.: 23.00 1st Qu.: 3.00
Median : 6.000 Median :183.0 Median : 66.00 Median : 9.00
Mean : 6.484 Mean :191.8 Mean : 71.34 Mean :12.15
3rd Qu.: 9.000 3rd Qu.:261.0 3rd Qu.: 117.00 3rd Qu.:18.00
Max. :12.000 Max. :400.0 Max. : 250.00 Max. :65.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :37.13 Min. :-6.600
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.07 1st Qu.:-4.680
Median :0.000000 Median : 0.0000 Median :40.70 Median :-3.764
Mean :0.000498 Mean : 0.1203 Mean :40.67 Mean :-3.352
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.65 3rd Qu.:-2.138
Max. :6.000000 Max. :229.0000 Max. :42.70 Max. : 2.438
altitud
Min. : 405.0
1st Qu.: 627.0
Median : 735.0
Mean : 777.2
3rd Qu.: 916.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:109.0 1st Qu.: 47.00 1st Qu.:171.0 1st Qu.:0
Median : 9.000 Median :129.0 Median : 72.00 Median :186.0 Median :0
Mean : 7.207 Mean :137.7 Mean : 74.05 Mean :203.4 Mean :0
3rd Qu.:11.000 3rd Qu.:152.5 3rd Qu.: 92.00 3rd Qu.:220.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00 Min. :28.31 Min. :-16.499 Min. : 4.0
1st Qu.: 0.00 1st Qu.:40.78 1st Qu.: -8.624 1st Qu.: 95.0
Median : 0.00 Median :42.24 Median : -8.411 Median : 263.0
Mean : 8.23 Mean :40.70 Mean : -6.597 Mean : 566.3
3rd Qu.: 0.00 3rd Qu.:42.89 3rd Qu.: -4.010 3rd Qu.: 370.0
Max. :607.00 Max. :43.36 Max. : 2.825 Max. :2400.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-102.0 Min. : 89.0 Min. :0
1st Qu.: 3.000 1st Qu.:121.0 1st Qu.: 57.0 1st Qu.:102.0 1st Qu.:0
Median :10.000 Median :145.0 Median : 80.0 Median :111.0 Median :0
Mean : 7.601 Mean :149.1 Mean : 80.7 Mean :115.1 Mean :0
3rd Qu.:11.000 3rd Qu.:175.5 3rd Qu.: 107.0 3rd Qu.:126.0 3rd Qu.:0
Max. :12.000 Max. :326.0 Max. : 211.0 Max. :163.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.80 1st Qu.: -8.411 1st Qu.: 32.0
Median : 0.000 Median :42.43 Median : -5.598 Median : 143.0
Mean : 2.786 Mean :41.45 Mean : -4.897 Mean : 310.9
3rd Qu.: 0.000 3rd Qu.:43.30 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :892.000 Max. :43.57 Max. : 3.035 Max. :2371.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 7.0 Min. :-62.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:143.0 1st Qu.: 65.00 1st Qu.:16.00
Median : 6.000 Median :179.0 Median : 96.00 Median :26.00
Mean : 6.419 Mean :180.8 Mean : 96.97 Mean :26.18
3rd Qu.: 9.000 3rd Qu.:219.0 3rd Qu.:133.00 3rd Qu.:36.00
Max. :12.000 Max. :340.0 Max. :202.00 Max. :59.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :39.47 Min. :-8.649
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:42.85 1st Qu.:-8.411
Median :0.0000000 Median : 0.00000 Median :43.31 Median :-5.873
Mean :0.0001935 Mean : 0.05853 Mean :43.11 Mean :-5.845
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:43.43 3rd Qu.:-3.819
Max. :2.0000000 Max. :40.00000 Max. :43.57 Max. :-1.008
altitud
Min. : 4.0
1st Qu.: 42.0
Median :108.0
Mean :176.5
3rd Qu.:336.0
Max. :656.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 19.00
Median : 6.000 Median : 72.00 Median : 6.00 Median : 30.00
Mean : 6.482 Mean : 80.96 Mean : 11.65 Mean : 34.35
3rd Qu.:10.000 3rd Qu.:131.00 3rd Qu.: 56.25 3rd Qu.: 47.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :122.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1572
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.9844 Median :2228
Mean :0 Mean : 13.97 Mean :41.99 Mean :-0.1576 Mean :2145
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)